'use strict';
function rank_by_two_large_one_small(collection){
  let result = [];
  let arr = collection.sort((a,b)=>a-b);

  for(let i = 0;i<arr.length;i+=3){
    let a = arr.slice(i,i+3);
    if(a.length === 3){
      let t = a[2];
      a[2] = a[0];
      a[0] =a[1];
      a[1] = t;
      for(let item of a){
        result.push(item);
      }
    }
    if(a.length <3){
      for(let item of a){
        result.push(item);
    }
    }
    
    //console.log(a);
  }
    
   console.log(result);
  
  }
 
rank_by_two_large_one_small([2, 8, 1, 9, 6, 4, 3, 10] );
module.exports = rank_by_two_large_one_small;
